package com.springStudy.beans.factory.config.demo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.springStudy.beans.factory.config.demo")
public class BeanFactoryPostProcessorTest {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(BeanFactoryPostProcessorTest.class);
        System.out.println("-------------  runtime use bean ------------------------");
        TestBean testBean = (TestBean)context.getBean("testBean");
        ((AnnotationConfigApplicationContext) context).destroy();

    }


    @Bean(initMethod = "initMethod",destroyMethod = "destroyMethod")
    public TestBean testBean() {
        System.out.println("声明一个Bean");
        return new TestBean();
    }

}
